package com.ship.boats.util;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;

import com.alibaba.fastjson.JSONObject;
import com.banboocloud.Codec.Sm3Signature;
import com.banboocloud.Codec.Sm4Cipher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;
import java.util.Iterator;
import java.util.Map;

/**
 * <b>LdentityAuthenticationUtil</b>
 *
 * @description: LdentityAuthenticationUtil <br>
 * @date: 2024/4/1 10:52 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */
public class LdentityAuthenticationUtil {
    private static final Logger logger = LoggerFactory.getLogger(LdentityAuthenticationUtil.class);

    public static String decrypt(String str, String key){
        Sm4Cipher sm4Cipher = new Sm4Cipher();
        String result2 = sm4Cipher.decrypt(str, key);
        logger.info("解密后数据信息:{}"+result2);
        return result2;
    }

    //签名与加密q
    public static String sign(Map<String, Object> param) {
        StringBuffer sb = new StringBuffer();
        Iterator<String> it = param.keySet().iterator();
        while (it.hasNext()) {
            String key = (String) it.next();
            sb.append(key).append("=").append(param.get(key)).append("&");
        }
        sb.deleteCharAt(sb.length() - 1);
        Sm3Signature signature = new Sm3Signature();
        System.out.println(sb.toString());
        String sign = signature.signature(sb.toString());
        param.put("signature", sign);
        return JSONObject.toJSONString(param);
    }

    public static void main(String[] args) {
        String str = "entrade-gaspower";
        String format = DateUtil.format(new Date(), DatePattern.PURE_DATE_FORMATTER);
        String data ="L8OYQ4ntOI9QGIxBxFZ5ZOjVkkKcD6KWmJeFqAJ9wmXUZJJqdfLhpvkKACD/rS20HD2/Zk4qFYjGOtQCDdphtGf8ziu9NOxp8e/QoDUe5aMydh7G264y71mwY5VBmPcl0RJJRBGRTakmEJu9PikfH8MkxK7LVwjzgBHkqlt1dezln9CEqUsKsYoQ7u5HsP+dAE4ERSa5s5RHrscrfRdoj+pLsavM7N+HUGGWs5DO4BOJzX7PleY0TmPKgmWC17KI3Hr/cR/cN3XpYHSO19LxDTWGRgpq4CFbWv+p5pIEj+8cGYb0hJB4zPvW/Gw+0anPjWAenjKX8I2TMx7l9XMLPiiJ2+CJn94AUXs+RknbaRaan6kwX5+brqQyrU5lrhdigSwxIqLTQ89XWHwtHpI7x1vYrdQS+rFOiq+UaOL25qYYFOmUeUU4FNwQbkE6pm6ZFWAecttd5mc80f4jEuwGEeVT79hMe1vgkZHq281mT+o=";
        decrypt(data, str);


    }
}
